package com.example.its2021606134chh.BusModule;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.its2021606134chh.R;

import java.util.List;

/**
 * @ClassName: BusLineRViewAdapter$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 19/8/2021$
 * @Version: 1.0
 */
public class BusLineRViewAdapter extends RecyclerView.Adapter<BusLineRViewAdapter.ViewHolder> {
    List<rvBusLineData> list;
    public BusLineRViewAdapter(List<rvBusLineData> list) {
        this.list = list;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_busline,  parent, false);
        return new BusLineRViewAdapter.ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        rvBusLineData busLineData = list.get(position);
        holder.tvItemBusLine.setText(busLineData.getBusline_name() + " (" + busLineData.getStart_place() + "-" + busLineData.getEnd_place() + ")");
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvItemBusLine;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvItemBusLine = itemView.findViewById(R.id.tvItemBusLine);
        }
    }
}
